<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-1-31
 * Time: 上午10:19
 */

namespace common\models;

/**
 * Class CarOrder
 * @package common\models
 *
 * @property Custom $custom
 * @property CarOrderLog[] $carOrderLogs
 * @property CarOrderLog $lastCarOrderLog
 */
class CarOrder extends \common\models\base\CarOrder
{
    const TYPE_NEW = 10; // 新车
    const TYPE_USED = 11; // 二手车
    const RESUBMIT_FIRST = 0; // 申请
    const RESUBMIT_BACK_RESUB = 1; // 继续申请（被退回的）
    const RESUBMIT_ADD = 2; // 资料补充

    public static function getType()
    {
        return [
            self::TYPE_NEW => '新车',
            self::TYPE_USED => '二手车',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCustom()
    {
        return $this->hasOne(Custom::className(), ['id' => 'custom_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCarOrderLogs()
    {
        return $this->hasMany(CarOrderLog::className(), ['car_order_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLastCarOrderLog()
    {
        return $this->hasOne(CarOrderLog::className(), ['car_order_id' => 'id'])->orderBy(['id'=>SORT_DESC]);
    }
}